<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for src/utils/request.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="..\..\prettify.css" />
    <link rel="stylesheet" href="..\..\base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(..\..\sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="..\..\index.html">All files</a> / <a href="index.html">src/utils</a> request.js
    </h1>
    <div class='clearfix'>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" >import axios from 'axios'</span>
<span class="cstat-no" title="statement not covered" >import helper from './helper.js'</span>
<span class="cstat-no" title="statement not covered" >import qs from 'qs'</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >import Vue from 'vue';</span>
<span class="cstat-no" title="statement not covered" >import {Toast} from 'vant';</span>
<span class="cstat-no" title="statement not covered" >Vue.use(Toast);</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >if(process.env.NODE_ENV=='production'){</span>
<span class="cstat-no" title="statement not covered" >    axios.defaults.baseURL = process.env.API_HOST;</span>
}else{
<span class="cstat-no" title="statement not covered" >    axios.defaults.baseURL = '/'</span>
}
&nbsp;
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.withCredentials=true; //让ajax携带cookie
&nbsp;
function apiAxios(method, url, params, token='111') <span class="cstat-no" title="statement not covered" >{</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >  return new Promise(<span class="fstat-no" title="function not covered" >(</span>resolve,reject) =&gt; {</span>
<span class="cstat-no" title="statement not covered" >    axios({</span>
      method: method,
      //拼接参数
      url: method === 'GET'|| method === 'DELETE' ? helper.queryString(url,params) : url,
      data: method === 'POST' || method === 'PUT' ? qs.stringify(params) : null,
      timeout: 10000,
      // headers: { Authorization: `Bearer ${token}` },
      withCredentials: false
    })
    .then(<span class="fstat-no" title="function not covered" >response =&gt; </span>{
<span class="cstat-no" title="statement not covered" >      if(response.data.code == 1){</span>
        // console.log(response.data)
<span class="cstat-no" title="statement not covered" >        resolve(response.data.data);</span>
      }else{
        //Toast.fail(response.data.msg);
<span class="cstat-no" title="statement not covered" >        Toast({</span>
          message: response.data.msg,
          icon: 'cross',
        });
      }
    })
    .catch(<span class="fstat-no" title="function not covered" >err =&gt; </span>{
<span class="cstat-no" title="statement not covered" >      reject(err)</span>
    })
  })
}
&nbsp;
export default {
  get: <span class="fstat-no" title="function not covered" >function (</span>url, params, token) {
<span class="cstat-no" title="statement not covered" >    return apiAxios('GET', url, params, token)</span>
  },
  post: <span class="fstat-no" title="function not covered" >function (</span>url, params, token) {
<span class="cstat-no" title="statement not covered" >    return apiAxios('POST', url, params, token)</span>
  },
  put: <span class="fstat-no" title="function not covered" >function (</span>url, params, token) {
<span class="cstat-no" title="statement not covered" >    return apiAxios('PUT', url, params, token)</span>
  },
  delete: <span class="fstat-no" title="function not covered" >function (</span>url, params, token) {
<span class="cstat-no" title="statement not covered" >    return apiAxios('DELETE', url, params, token)</span>
  },
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Nov 27 2023 23:16:11 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="..\..\prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="..\..\sorter.js"></script>
</body>
</html>
